import Vue from 'vue'
//新创建一个vue实例
let v = new Vue()
const actions = {
  getInvestmenttype({ commit, state }, params) {
    v.axios
      .post('api-p/projectstats/expand/investmenttype', params)
      .then((res) => {
        let dataList = []
        let dataArr = res.data.result
        let replaceObj = { id: 'code', name: 'name' }
        for (let i = 0; i < dataArr.length; i++) {
          let dataObj = {}
          for (const k in replaceObj) {
            dataObj[k] = dataArr[i][replaceObj[k]]
          }
          dataList.push(dataObj)
        }
        if (!res.data.hasError) {
          commit('SET_INFO', ['investmentOptions', dataList])
        } else {
          commit('SET_INFO', ['investmentOptions', []])
        }
      })
      .catch(() => {
        commit('SET_INFO', ['investmentOptions', []])
      })
  },
  getStatus({ commit, state }, params) {
    v.axios
      .post('api-p/projectstats/expand/status', params)
      .then((res) => {
        if (!res.data.hasError) {
          commit('SET_INFO', ['statusOptions', res.data.result])
        } else {
          commit('SET_INFO', ['statusOptions', []])
        }
      })
      .catch(() => {
        commit('SET_INFO', ['statusOptions', []])
      })
  },
  getAreas({ commit, state }, params) {
    v.axios
      .post('api-bs/areadic/base/detailbyareaid', params)
      .then((res) => {
        if (!res.data.hasError) {
          commit('SET_INFO', ['areasOptions', res.data.result])
        } else {
          commit('SET_INFO', ['areasOptions', []])
        }
      })
      .catch(() => {
        commit('SET_INFO', ['areasOptions', []])
      })
  },
  //建筑行业接口
  getIndustry({ commit, state }, params) {
    v.axios
      .post('api-bs/base/dicitem/getuserindustry', params)
      .then((res) => {
        if (!res.data.hasError) {
          commit('SET_INFO', ['industryOptions', res.data.result])
        } else {
          commit('SET_INFO', ['industryOptions', []])
        }
      })
      .catch(() => {
        commit('SET_INFO', ['industryOptions', []])
      })
  },
  //非建行业接口（同时注册行业接口通用）
  getIndustryNC({ commit, state }, params) {
    v.axios
      .post('api-bs/industry/base/detailbyindustryid', params)
      .then((res) => {
        if (!res.data.hasError) {
          commit('SET_INFO', ['industryOptionsNC', res.data.result])
        } else {
          commit('SET_INFO', ['industryOptionsNC', []])
        }
      })
      .catch(() => {
        commit('SET_INFO', ['industryOptionsNC', []])
      })
  },
  /**
   * @name: 获取班组数据
   * @param {object} params = {projectId,uscc}
   * @Author: 471826078@qq.com
   */
  getGroupList({ commit, state }, params) {
    v.axios
      .post('api-e/cs/group/expand/findgroupbyuscc', params)
      .then((res) => {
        if (!res.data.hasError) {
          commit('SET_INFO', ['groupIdOptions', res.data.result])
        } else {
          commit('SET_INFO', ['groupIdOptions', []])
        }
      })
      .catch(() => {
        commit('SET_INFO', ['groupIdOptions', []])
      })
  },
  // 获取户籍数据
  getLiveAddressList({ commit, state }, params) {
    v.axios
      .post('api-bs/areadic/base/getCensus', params)
      .then((res) => {
        if (!res.data.hasError) {
          commit('SET_INFO', ['liveAddressOptions', res.data.result])
        } else {
          commit('SET_INFO', ['liveAddressOptions', []])
        }
      })
      .catch(() => {
        commit('SET_INFO', ['liveAddressOptions', []])
      })
  },
}

export default actions
